home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Information / CSMP Digest / volume 1 / csmp-v1-139.txt < prev    next >
Text File  |  1992-12-31  |  61KB  |  1,490 lines

  1. C.S.M.P. Digest             Mon, 13 Jul 92       Volume 1 : Issue 139
  2.  
  3. Today's Topics:
  4.  
  5.     Instance Variables moving in Think C - How to stop
  6.     Dynamic Runtime Method Dispatch (Was Re: Is System 7 written in C++?)
  7.     Correctly handling long tasks
  8.     Screensaver erasurE
  9.     Getting User's Color Control Panel Settings
  10.     Icons dragging
  11.     Is This Fond PostScript ?!
  12.     Warning: THINK Pascal glue for GetZoneList is dangerous!
  13.  
  14.  
  15.  
  16. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  17.  
  18. The digest is a collection of article threads from the internet newsgroup
  19. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  20. regularly and want an archive of the discussions.  If you don't know what a
  21. newsgroup is, you probably don't have access to it.  Ask your systems
  22. administrator(s) for details.  (This means you can't post questions to the
  23. digest.)
  24.  
  25. Each issue of the digest contains one or more sets of articles (called
  26. threads), with each set corresponding to a 'discussion' of a particular
  27. subject.  The articles are not edited; all articles included in this digest
  28. are in their original posted form (as received by our news server at
  29. cs.uoregon.edu).  Article threads are not added to the digest until the last
  30. article added to the thread is at least one month old (this is to ensure that
  31. the thread is dead before adding it to the digest).  Article threads that
  32. consist of only one message are generally not included in the digest.
  33.  
  34. The entire digest is available for anonymous ftp from ftp.cs.uoregon.edu
  35. [128.223.8.8] in the directory /pub/mac/csmp-digest.  The most recent issues
  36. are available from sumex-aim.stanford.edu [36.44.0.6] in the directory
  37. /info-mac/digest/csmp.  If you don't have ftp capability, the sumex archive
  38. has a mail server; send a message with the text '$MACarch help' (no quotes)
  39. to LISTSERV@ricevm1.rice.edu for more information.
  40.  
  41. These digest is also available via email.  Just send a note saying that you
  42. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  43. automatically receive each new issue as it is created.  Sorry, back issues
  44. are not available through the mailing list.
  45.  
  46. Send administrative mail to mkelly@cs.uoregon.edu.
  47.  
  48.  
  49. -------------------------------------------------------
  50.  
  51. From: caw@cs.mu.OZ.AU (Chris Wright)
  52. Subject: Instance Variables moving in Think C - How to stop
  53. Organization: Computer Science, University of Melbourne, Australia
  54. Date: Sun, 7 Jun 1992 12:35:19 GMT
  55.  
  56. When defining a class in Think C, which has char array instance vars,
  57. it seems important to remember that many of the standard ANSI calls
  58. could compact memory.e.g.:
  59. struct person : indirect {
  60.     char name[10];
  61.     void SetName(char *);
  62.     void PrintMessage( void );
  63.     };
  64.  
  65. void person::SetName(char* theName)
  66. {
  67.     strcpy(name, theName);
  68. }
  69.  
  70. void PrintMessage( void )
  71. {
  72.     printf("My name is %s", name);
  73. }
  74.  
  75. This doesn't always print out with the right name, 'cos I think memory
  76. is being compacted, and as classes are addressed as handles, we are in
  77. trouble. 
  78.  
  79. Does this mean that I have to surround all ANSI type calls with HLock() and
  80. HUnlock()?
  81.  
  82. Help would be appreciated...
  83.  
  84. chris
  85.  
  86.  
  87.  
  88. +++++++++++++++++++++++++++
  89.  
  90. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  91. Organization: Kalamazoo College
  92. Date: Sun, 7 Jun 1992 13:02:58 GMT
  93.  
  94. caw@cs.mu.OZ.AU (Chris Wright) writes:
  95. >When defining a class in Think C...
  96. >it seems important to remember that many of the standard ANSI calls
  97. >could compact memory.e.g.:
  98. >
  99. >void person::SetName(char* theName)
  100. >{
  101. >    strcpy(name, theName);
  102. >}
  103. >
  104. >...I think memory
  105. >is being compacted, and as classes are addressed as handles, we are in
  106. >trouble. 
  107. >
  108. >Does this mean that I have to surround all ANSI type calls with HLock() and
  109. >HUnlock()?
  110.  
  111. We just finished discussing this in the tcl-talk discussion list.  When
  112. you call strcpy(), if the segment with the ANSI library isn't loaded, it
  113. has to pull it in.  That's what causes memory to move.
  114.  
  115. Either you have to (1) lock "this" every time you call a function in
  116. another segment, or (2) make sure the function's segment won't be
  117. purged.
  118.  
  119. (1):  The best way to do this is:
  120. {    Boolean wasLocked; wasLocked = Lock(TRUE);
  121.     // do your stuff
  122.     Lock(wasLocked);    }
  123.  
  124. (2):  You can stick the function in the main() segment, or the calling
  125. segment, or you can make a dummy reference to it early in the program
  126. and just never call UnloadSeg on it.  Either way, it'll always be
  127. available.
  128.  
  129. I prefer (1), but it requires a lot of extra typing and planning.  If
  130. you do (2), realize that you may never be able to go back to (1)--if you
  131. code with the assumption that calls across segments won't move memory,
  132. you'll always have to have all segments loaded.  This may kick up your
  133. app's memory requirements quite a lot.
  134. - -- 
  135.  Jamie McCarthy     Internet: k044477@kzoo.edu     AppleLink: j.mccarthy
  136.  Tact is the art of making a point without making an enemy.
  137.    - Howard W. Newton
  138.  
  139. +++++++++++++++++++++++++++
  140.  
  141. From: mspace@netcom.com (Brian Hall)
  142. Date: Sun, 07 Jun 92 23:57:26 GMT
  143. Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
  144.  
  145. caw@cs.mu.OZ.AU (Chris Wright) writes:
  146.  
  147. >When defining a class in Think C, which has char array instance vars,
  148. >it seems important to remember that many of the standard ANSI calls
  149. >could compact memory.e.g.:
  150. >struct person : indirect {
  151. >    char name[10];
  152. >    void SetName(char *);
  153. >    void PrintMessage( void );
  154. >    };
  155.  
  156. >Does this mean that I have to surround all ANSI type calls with HLock() and
  157. >HUnlock()?
  158.  
  159. Just the ones that may actually move memory.  printf is quite likely, but
  160. strcpy is safe.  Since you get the sources, just take a look at them.
  161. If things like strcpy and strcat are in asm, or use blockmove, you don't
  162. need to worry - they won't move memory.
  163.  
  164. - -- 
  165.  
  166.  \ | /   | Brian Hall                 mspace@netcom.com
  167.  - : -   | Mark/Space Softworks       Applelink: markspace
  168.   /|\    |                            America Online: MarkSpace
  169.  |-+-|   |
  170. /-\|/-\  | People don't kill people, toasters kill people.
  171.  
  172. +++++++++++++++++++++++++++
  173.  
  174. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  175. Date: 8 Jun 92 02:51:52 GMT
  176. Organization: Kalamazoo College
  177.  
  178. mspace@netcom.com (Brian Hall) writes:
  179. >caw@cs.mu.OZ.AU (Chris Wright) writes:
  180. >
  181. >>it seems important to remember that many of the standard ANSI calls
  182. >>could compact memory...
  183. >>
  184. >>Does this mean that I have to surround all ANSI type calls with HLock() and
  185. >>HUnlock()?
  186. >
  187. >Just the ones that may actually move memory.  printf is quite likely, but
  188. >strcpy is safe.
  189.  
  190. Not if it's in a different segment.  Any cross-segment function call can
  191. cause memory to be moved, unless you take steps to ensure otherwise
  192. (namely, loading the segment in beforehand and never UnloadSeg'ing it).
  193.  
  194. This usually happens with ANSI since ThC's ANSI library is about 5K
  195. short of the maximum segment size, so most calls to it are from a
  196. different segment.
  197. - -- 
  198.  Jamie McCarthy     Internet: k044477@kzoo.edu     AppleLink: j.mccarthy
  199.  To exit to shell in the mini-debugger, enter SM 0 A9 F4 and then G 0.
  200.  
  201. +++++++++++++++++++++++++++
  202.  
  203. From: jstevens@crick.ssctr.bcm.tmc.edu (Jason Philip Stevens)
  204. Date: 8 Jun 1992 15:11:57 GMT
  205. Organization: Baylor College of Medicine, Houston, Tx
  206.  
  207.  
  208. In article <9215922.21843@mulga.cs.mu.OZ.AU>, caw@cs.mu.OZ.AU (Chris Wright) writes:
  209. |> When defining a class in Think C, which has char array instance vars,
  210. |> it seems important to remember that many of the standard ANSI calls
  211. |> could compact memory.e.g.:
  212. |> struct person : indirect {
  213. |>     char name[10];
  214. |>     void SetName(char *);
  215. |>     void PrintMessage( void );
  216. |>     };
  217. |> 
  218. |> void person::SetName(char* theName)
  219. |> {
  220. |>     strcpy(name, theName);
  221. |> }
  222. |> 
  223. |> void PrintMessage( void )
  224. |> {
  225. |>     printf("My name is %s", name);
  226. |> }
  227.                 ^ I assume this 'name' actually the char* passed
  228.                   to SetName as 'theName' rather than the instance
  229.                   variable in class person...
  230.  
  231. |> This doesn't always print out with the right name, 'cos I think memory
  232. |> is being compacted, and as classes are addressed as handles, we are in
  233. |> trouble. 
  234. |> 
  235. |> Does this mean that I have to surround all ANSI type calls with HLock() and
  236. |> HUnlock()?
  237. |> 
  238. |> Help would be appreciated...
  239.  
  240. Well, I'll take a stab at it...
  241.  
  242. if you have:
  243.  
  244. person* someGuy;
  245. char* hisName;
  246.  
  247. someGuy = new person;
  248. someGuy->name = "someName";    /* As an instance variable of a class, this
  249.                    pointer should not be passed to any routine
  250.                    that moves memory (as listed in IM6 appendix */
  251. someGuy->SetName(hisName);    /* 'hisName' is now a copy of the string, in
  252.                    someGuy->name, rather than a copy of pointer.
  253.                    As such, while someGuy->name may get moved,
  254.                    'hisName' will not (it's not an instance
  255.                    variable or a pointer to an instance
  256.                    variable) */
  257. PrintMessage(hisName);        /* Perhaps this is a matter of taste, but this
  258.                    really should take an argument.  Is also makes
  259.                    it clear exactly which version of 'name' you
  260.                    mean, since in the code fragment above there
  261.                    _is_ no global variable called 'name'... */
  262.  
  263. This should work (I hope).
  264.  
  265. - -jps
  266.  
  267. - -- 
  268. Jason Stevens            Internet:  jstevens@bcm.tmc.edu
  269. Network User Services        Voice:  (713) 798-7370
  270. Baylor College of Medicine    Opinions expressed are mine alone.
  271.  
  272.  
  273. +++++++++++++++++++++++++++
  274.  
  275. From: larrym@mtxinu.COM (Larry Meyer - mac weenie)
  276. Date: 9 Jun 92 18:43:44 GMT
  277. Organization: Xinet, Berkeley
  278.  
  279. In article <4=-lzmq.mspace@netcom.com> mspace@netcom.com (Brian Hall) writes:
  280. >caw@cs.mu.OZ.AU (Chris Wright) writes:
  281. >
  282. >>When defining a class in Think C, which has char array instance vars,
  283. >>it seems important to remember that many of the standard ANSI calls
  284. >>could compact memory.e.g.:
  285. >>struct person : indirect {
  286. >> (...stuff deleted...)
  287. >>Does this mean that I have to surround all ANSI type calls with HLock() and
  288. >>HUnlock()?
  289. >
  290. >Just the ones that may actually move memory.  printf is quite likely, but
  291. >strcpy is safe.  Since you get the sources, just take a look at them.
  292. >If things like strcpy and strcat are in asm, or use blockmove, you don't
  293. >need to worry - they won't move memory.
  294. >
  295.  
  296. I agree that one can assume that something as trivial as strcpy will
  297. never trigger memory movement, but I'd just like to emphasize that you
  298. have to be real careful about such assumptions.  for example, I once
  299. had a problem with using qsort() on an array stored in an unlocked
  300. Handle.  I was getting bizarre results in my callback routine, and of
  301. course it turned out that memory was getting compacted. Obviously, one
  302. would naively think that qsort would never use dynamic memory (one of
  303. the features of this algo is that it operates "in place" on an array
  304. and requires no scratch memory). I never looked into it, but I suspect
  305. that the memory movement occurred because of some initialization
  306. calls within qsort.
  307.  
  308. i.e. it seems safe to say that one should assume that ANY non-trivial
  309. ANSI call may move memory (unless Symantec actually documents
  310. which calls do move memory, a-la Apple's list). 
  311. /*************************************************************
  312. Larry Meyer Mac/Unix Programmer @ Xinet, Berkeley CA
  313. larrym@xinet.com 
  314. *************************************************************/
  315. - -- 
  316. /*************************************************************
  317. Larry Meyer Mac/Unix Programmer @ Xinet, Berkeley CA
  318. larrym@xinet.com (ask me about max<->unix stuff)
  319.  
  320. ---------------------------
  321.  
  322. From: orpheus@reed.edu (P. Hawthorne)
  323. Subject: Dynamic Runtime Method Dispatch (Was Re: Is System 7 written in C++?)
  324. Date: 8 Jun 92 06:01:17 GMT
  325. Organization: Reed College, Portland, Oregon
  326.  
  327.  
  328.   Prometheus Hawthorne exclaims:
  329. > My kingdom for a new and improved object method dispatching technique!
  330.  
  331.   Bruce Hoult asserts:
  332. > The method dispatch code possible with C++ [....] is about as efficient as
  333. > it's possible to get.
  334.  
  335.   Kent Sandvik laments:
  336. > And no dynamic runtime method dispatching, something that Objective-C has.
  337.  
  338.  
  339.   What good is inheritance without dynamic runtime method dispatch?
  340.  
  341.   For special cases where it is obvious to me that only one class could be
  342. receiving, I would be okay with prefacing the method call with a keyword.
  343. I could even accept some special case for messages sent to self, but for
  344. my purposes, dynamic dispatch should be the default.
  345.  
  346.   I wish there was a way for me to disassemble some Objective C.... Hmmm.
  347. If you assume that there is a class tag at the start of an instance, a
  348. method call could consist of pushing the address of the dispatch table plus
  349. the class tag plus the method selector... Duh.
  350.  
  351.   Suppose I came up with a low instruction-count dispatching technique.
  352. I'd have to write a compiler, or evangelize like crazy. I guess this is a
  353. case of just doing it before doing it fast. 
  354.  
  355.   Back to the old source editor,
  356.   Theus (orpheus@reed.edu)
  357.  
  358. +++++++++++++++++++++++++++
  359.  
  360. From: lsr@taligent.com (Larry Rosenstein)
  361. Date: 10 Jun 92 01:48:16 GMT
  362. Organization: Taligent, Inc.
  363.  
  364. In article <1992Jun8.060117.28937@reed.edu>, orpheus@reed.edu (P. Hawthorne)
  365. writes:
  366. >  Bruce Hoult asserts:
  367. > > The method dispatch code possible with C++ [....] is about as efficient as
  368. > > it's possible to get.
  369. >   Kent Sandvik laments:
  370. > > And no dynamic runtime method dispatching, something that Objective-C has.
  371. >   What good is inheritance without dynamic runtime method dispatch?
  372.  
  373. What Kent is referring to is the ability to send any message to any object.  You
  374. can't do this in C++ because everything is type-checked at compile time.  You
  375. can do this in Lisp or Smalltalk or Objective-C where there are no types (or
  376. they are optional).  The price for this flexibility is that the message mightg
  377. not be understood by the object, and that the dispatching is a bit slower.
  378.  
  379. C++ has virtual function calls in which the exact code that gets run is not
  380. determined until runtime.  I agree with Bruce that the C++ implementation is
  381. about as fast you can get, at the cost of using extra memory for vtable
  382. (compared to MPW Object Pascal, for example).
  383.  
  384. >   For special cases where it is obvious to me that only one class could be
  385. > receiving, I would be okay with prefacing the method call with a keyword.
  386. > I could even accept some special case for messages sent to self, but for
  387. > my purposes, dynamic dispatch should be the default.
  388.  
  389. In fact, in MPW Object Pascal this kind of optimization is made at link-time
  390. based on how the code was written.  If there is only one implementation of a
  391. method then the call doesn't go through any dispatcher at all.  This is
  392. different from C++ where you have to make a function virtual or not.  I agree
  393. with you that virtual should have been the default in C++.
  394.  
  395. > method call could consist of pushing the address of the dispatch table plus
  396. > the class tag plus the method selector... Duh.
  397.  
  398. Actually you need to push the receiver, so you can get the class information
  399. from that.  
  400.  
  401. In general a method dispatcher is a function that maps the class ID gotten from
  402. the receiver and the method ID that the caller pushes to the function that you
  403. want to call.  (You can extend this to take into account class IDs from more
  404. than one parameter.)
  405.  
  406. In C++, the method ID happens to be an index into the vtable that the compiler
  407. computes at compile-time.  Also, the mapping is done inline with the call, so
  408. the dispatching is very fast.
  409.  
  410. In something like Objective-C, the compiler can't compute something like an
  411. index at compile time, because you can send any message to any object.  Instead
  412. the dispatcher has to do more of a lookup at runtime.  Generally, you would use
  413. a hash table to speed this up.
  414.  
  415. (Actually, if you wanted to there's no reason why you couldn't implement more
  416. dynamic dispatching in C++.  C++ supports taking pointers to member functions,
  417. and once you have that it's pretty easy to store these pointers in tables, look
  418. them up, etc.)
  419.  
  420. - --
  421. Larry Rosenstein
  422. Taligent, Inc.
  423. lsr@taligent.com
  424.  
  425. ---------------------------
  426.  
  427. From: Adrian C Ruigrok
  428. Subject: Correctly handling long tasks
  429. Date: 8 Jun 92 13:41:44 GMT
  430. Organization: Bell-Northern Research
  431.  
  432. In communications applications, like MacTCP and Appletalk apps, it is common to
  433. be stuck waiting for another machine to respond for 15s or longer.  When there
  434. is a timeout in progress, you can be out of touch for a very long time.  What
  435. is the best way to at least let the user use his other applications?
  436.  
  437. I would have thought that you would be able to do something with asynchronous
  438. calls something like this
  439.  
  440.  
  441. MyAsyncCall()
  442. while (not done my async called stuff) {
  443.   WaitNextEvent(...)   // so others can do something at least
  444. }
  445.  
  446.  
  447. What I am not sure of is whether WaitNextEvent is the best way, and what the
  448. parameters to WaitNextEvent would be.
  449.  
  450. I am told that there is a problem with WaitNextEvent that prevents you from
  451. using it in this context.  However, I can't think what else to do, and there
  452. has to be a better way to do things than a synchronous call!
  453.  
  454. Thanks,
  455. Adrian 
  456.  
  457.  
  458. - ---------------------------------------------------
  459. Adrian Ruigrok
  460. Bell-Northern Research
  461. Ottawa, Canada 
  462.  
  463. +++++++++++++++++++++++++++
  464.  
  465. From: peirce@outpost.SF-Bay.org (Michael Peirce)
  466. Date: 9 Jun 92 01:05:12 GMT
  467. Organization: Peirce Software
  468.  
  469.  
  470. In article <1992Jun8.134144.15334@bwdls61.bnr.ca> (comp.sys.mac.programmer), Adrian C Ruigrok writes:
  471. > In communications applications, like MacTCP and Appletalk apps, it is common to
  472. > be stuck waiting for another machine to respond for 15s or longer.  When there
  473. > is a timeout in progress, you can be out of touch for a very long time.  What
  474. > is the best way to at least let the user use his other applications?
  475. > I would have thought that you would be able to do something with asynchronous
  476. > calls something like this
  477. > MyAsyncCall()
  478. > while (not done my async called stuff) {
  479. >   WaitNextEvent(...)   // so others can do something at least
  480. > }
  481. > What I am not sure of is whether WaitNextEvent is the best way, and what the
  482. > parameters to WaitNextEvent would be.
  483. > I am told that there is a problem with WaitNextEvent that prevents you from
  484. > using it in this context.  However, I can't think what else to do, and there
  485. > has to be a better way to do things than a synchronous call!
  486.  
  487. Here's a snippet of code I've used in the past.  You call this where
  488. you have you WaitNextEvent and makes for slightly cleaner code.
  489.  
  490. PROCEDURE YieldTime;
  491. CONST
  492.     noEvent = 0;
  493. VAR
  494.     event        : EventRecord;
  495. BEGIN {YieldTime}
  496.  
  497.     IF WaitNextEvent(noEvent, event, 1, NIL) THEN ;
  498.  
  499. END; {YieldTime}
  500.  
  501. This approach is OK for moderately quick & dirty use, but two things
  502. would be better:
  503.  
  504. (1) Put up a dialog if things are taking more than a short amount
  505. of time.  Let the user cancel the operations if they want.
  506.  
  507. (2) Don't get into this situation in the first place.  Use a state
  508. machine and poll for the completion of steps in the main event loop. 
  509. This lets the user get work done while waiting.
  510.  
  511.  
  512. - --  Michael Peirce      --   peirce@outpost.SF-Bay.org
  513. - --  Peirce Software     --   Suite 301, 719 Hibiscus Place
  514. - --  Makers of...        --   San Jose, California USA 95117
  515. - --                      --   voice: (408) 244-6554 fax: (408) 244-6882
  516. - --     SMOOTHIE         --   AppleLink: peirce & America Online: AFC Peirce
  517.  
  518. ---------------------------
  519.  
  520. From: jryan@adobe.com (Jim Ryan)
  521. Subject: Screensaver erasurE
  522. Organization: Adobe Systems, Inc.
  523. Date: Mon, 8 Jun 1992 18:50:44 GMT
  524.  
  525. I'm drawing a few picts, textEdit fields, and scrollbars in a modal dialog... 
  526. the problem is that when a screensaver kicks in and then out, the picts
  527. and the TE aren't redrawn.  To fix the problem, I looked
  528. for " if (dialogEvent->what == updateEvt) {" in my dialogFilter, and recalled 
  529. the function that draws the picts, and did a TEUpdate for the text... however,
  530. this causes the text to flicker like crazy in the dialog, as apparently
  531. once the updateEvt is a go, ModalDialog keeps calling it.  The picts 
  532. don't flicker, but if the cursor is placed over them, then the cursor flickers, 
  533. which would indicate to me that it's being redrawn repeatedly, as the text
  534. seems to be.  I thought I'd be clever and set dialogEvent->what to something
  535. else, like nullEvent, after doing my redrawing so ModalDialog wouldn't
  536. keep falling into my "if", but then the controls, etc., weren't redrawn, as 
  537. was the case If I returned TRUE.
  538.  
  539. Q: Is there a better way to do this, and/or what might I be doing
  540. wrong that's causing the flicker.  How do YOU redraw your modal dialogs
  541. after a screensaver erases everything?  Any hints would be most graciously
  542. welcomed.
  543.  
  544. Thanks a bunch,
  545. jr
  546.  
  547. place the usual and unusual disclaimers here... or there... or...
  548.  
  549. +++++++++++++++++++++++++++
  550.  
  551. From: absurd@applelink.apple.com (Tim Dierks, software saboteur)
  552. Date: 8 Jun 92 19:58:15 GMT
  553. Organization: MacDTS Misfits
  554.  
  555. In article <1992Jun8.185044.29228@adobe.com>, jryan@adobe.com (Jim Ryan) writes:
  556. > I'm drawing a few picts, textEdit fields, and scrollbars in a modal dialog... 
  557. > the problem is that when a screensaver kicks in and then out, the picts
  558. > and the TE aren't redrawn.  To fix the problem, I looked
  559. > for " if (dialogEvent->what == updateEvt) {" in my dialogFilter, and recalled 
  560. > the function that draws the picts, and did a TEUpdate for the text... however,
  561. > this causes the text to flicker like crazy in the dialog, as apparently
  562. > once the updateEvt is a go, ModalDialog keeps calling it.  The picts 
  563. > don't flicker, but if the cursor is placed over them, then the cursor flickers, 
  564. > which would indicate to me that it's being redrawn repeatedly, as the text
  565. > seems to be.  I thought I'd be clever and set dialogEvent->what to something
  566. > else, like nullEvent, after doing my redrawing so ModalDialog wouldn't
  567. > keep falling into my "if", but then the controls, etc., weren't redrawn, as 
  568. > was the case If I returned TRUE.
  569. > Q: Is there a better way to do this, and/or what might I be doing
  570. > wrong that's causing the flicker.  How do YOU redraw your modal dialogs
  571. > after a screensaver erases everything?  Any hints would be most graciously
  572. > welcomed.
  573.  
  574. What you need to do is detect and respond to update events.  There are two
  575. ways to do this, on better than the other.  One way is to put in a dialog
  576. event filter which will redraw your stuff when it gets an update event.
  577. The better way is to use user items for all your "special" items; then the
  578. dialog manager will take care of calling your function to draw the items
  579. when they need it.
  580.  
  581. Tim Dierks
  582. MacDTS, but I speak for my knees
  583.  
  584. +++++++++++++++++++++++++++
  585.  
  586. From: bm125@eng.cam.ac.uk (B. Maxwell)
  587. Date: 9 Jun 92 09:55:19 GMT
  588. Organization: Cambridge University Engineering Department, England
  589.  
  590. In article <1992Jun8.185044.29228@adobe.com> jryan@adobe.com (Jim Ryan) writes:
  591. >I'm drawing a few picts, textEdit fields, and scrollbars in a modal dialog... 
  592. >the problem is that when a screensaver kicks in and then out, the picts
  593. >and the TE aren't redrawn. 
  594.  
  595. ...
  596.  
  597. >
  598. >Q: Is there a better way to do this, and/or what might I be doing
  599. >wrong that's causing the flicker.  How do YOU redraw your modal dialogs
  600. >after a screensaver erases everything?  Any hints would be most graciously
  601. >welcomed.
  602. >
  603. >Thanks a bunch,
  604. >jr
  605.  
  606.  
  607. You should use the following procedure to redraw non-standard items in
  608. a dialog box.
  609.  
  610. 1) declare a userItem in your dialog item list that has a rectangle the size
  611. of your pict, or TEfield, or Scrollbars, etc..  (you can also set the rectangle 
  612. dynamically using SetDItem(...)
  613.  
  614. 2) setup a structure that contains all of your necessary handles and put a
  615. pointer to it in the reference constant of the dialog window so that you can
  616. get the handles to your picts, scrollbars, and textedit field.
  617.  
  618. 3) write the following routine that does nothing but draw a picture, or update a TE field,
  619.    or update a control. etc.
  620.  
  621. pascal void myDrawDlogItems(dptr,item)
  622.     DialogPtr dptr;
  623.     short item;
  624. {
  625.     PicHandle thePict;
  626.     myStructure *ms;
  627.  
  628.     /*get the reference constant, I think this call is right*/
  629.     ms = (myStructure *)GetWRefCon(dptr);
  630.  
  631.     /*might want to set the port just to make sure*/
  632.     SetPort(dptr);
  633.  
  634.     switch(item) {
  635.         case PictItem:
  636.             DrawPicture(ms->myPict,&((**(ms->myPict)).picFrame));
  637.             break;
  638.         case TEItem:
  639.             TEUpdate(&thePort->portRect,ms->myTEField);
  640.             break;
  641.  
  642.         ... and so on
  643.  
  644.     }
  645.  
  646.     return;
  647. }
  648.  
  649. Now, before calling ModalDialog the first time,  just install this routine for 
  650. each of the items using SetDItem as in the following calls.
  651.  
  652. GetDItem(dptr,ItemID,&itemType,&itemHandle,&itemRect);
  653. SetDItem(dptr,ItemId,itemType,(ProcPtr)myDrawDlogItems,&itemRect);
  654.  
  655. Because your item is a userItem type, whenever there is an update event, ModalDialog
  656. will now call your update routine to draw each of the items.  You don't have to worry
  657. about update events in your filter routine anymore.
  658.  
  659. You may need to mess around with the order of your userItems in the dialog item list
  660. depending upon if the rectangles overlap and if you want events from the items underneath.
  661. Otherwise, this is a clean way to do a messy job.
  662.  
  663. Have fun,
  664.  
  665. - --Bruce
  666.  
  667. ---------------------------
  668.  
  669. From: edw@caligula.cts.com (Ed Watkeys)
  670. Subject: Getting User's Color Control Panel Settings
  671. Date: Mon, 8 Jun 92 13:00:40 EDT
  672. Organization: Distant Software
  673.  
  674. I'm writing a program where where I'd like to use the colors that the user
  675. has selected in the Color Control Panel. In addition to the highlight color,
  676. I'd like to use the window colors in the content area of my document window.
  677. If I had it my way, I'd use the standard colors, which look the nicest, however
  678. you might come across a user who likes ugly colors :)
  679.  
  680. Ed
  681.  
  682. - --
  683. Edwin H. Watkeys III                       System Administrator
  684. edw@caligula.cts.com                           Distant Software
  685. AOL: EdWatkeys
  686.  
  687. +++++++++++++++++++++++++++
  688.  
  689. From: nerm@apple.com (Dean Yu)
  690. Date: 9 Jun 92 00:19:19 GMT
  691. Organization: Apple Computer, Inc.
  692.  
  693. In article <01050133.5i2jnp@caligula.cts.com>, edw@caligula.cts.com (Ed Watkeys) writes:
  694. > I'm writing a program where where I'd like to use the colors that the user
  695. > has selected in the Color Control Panel. In addition to the highlight color,
  696. > I'd like to use the window colors in the content area of my document window.
  697. > If I had it my way, I'd use the standard colors, which look the nicest, however
  698. > you might come across a user who likes ugly colors :)
  699. > Ed
  700.  
  701.   Color saves its changes into the default 'wctb' and 'cctb' resources
  702. in the system file.  You can use the call GetAuxWin() to get the colors
  703. that are used for the different parts of the windows and scroll bars.
  704.  
  705.   -- Dean Yu
  706.      Blue Meanie, Negative Ethnic Role Model, etc.
  707.      Apple Computer, Inc.
  708.      blah blah blah blah...
  709.  
  710. ---------------------------
  711.  
  712. From: mgraf@sydvm1.VNET.IBM.COM (Michael Graf)
  713. Date: Tue, 9 Jun 92 12:10:38 EST
  714. Subject: Icons dragging
  715. Organization: Australian Programming Centre (IBMA)
  716.  
  717.   As a novice (but learning) MAC Toolbox programmer, I would like to
  718. provide a nivce interface on an application that I am developing. What I
  719. would like to provide is the means for a user to 'drag' an icon across a
  720. screen and leave it in the new position. Obviously, determining MOUSE DOWNs
  721. in the icon is easy, but I am wondering what the best methodology to use is.
  722.  
  723.   Can anyone 'point' me in the correct direction; what toolbox calls should
  724. I be using ? Are there any snippets or source code around that does this
  725. sort of thing ?
  726.  
  727.   Ideally, later one I would love to be able to do the drag and leave the
  728. background (currently only a white window) the same. Is the same method the
  729. best or is there a better alternative.
  730.  
  731.   Things to note:
  732.     - I currently simply use colour ICONS (CICN in fact), but could use PICTs
  733.      if it is better. I used icons as I only needed fixed sized pictures.
  734.     - I have NO idea how to perform graphic manipulations, as such, so this
  735.      is a learning exercise for me in MOST (ALL) ways. Please be as explicit
  736.      as possible.
  737.     - I use THINK Pascal, but can read C code as well. The actual calls I
  738.      should be looking at are the major thing I need, though source code is
  739.      of course most welcome.
  740.     - Any hints to sections of Inside Mac that I should refer to are also
  741.      welcome.
  742.     - I would like to use colour for the 'dragged' items, and later on for the
  743.      background of the window they are dragged in
  744.     - Lastly, this is NOT a Finder program, but should support similar drag
  745.      and drop aspects.
  746.  
  747.   Any help or advice would be most appreciated.
  748.     Thanx, in advance, for the pointers....
  749.  
  750.  
  751. **********************************************************************
  752. Regards,
  753.   Michael Graf                             (mgraf@sydvm1.vnet.ibm.com)
  754. **********************************************************************
  755.  
  756. +++++++++++++++++++++++++++
  757.  
  758. From: zobkiw@world.std.com (Joe Zobkiw)
  759. Date: 9 Jun 92 12:34:02 GMT
  760. Organization: The World Public Access UNIX, Brookline, MA
  761.  
  762. To drag an icons outline (like the Finder) you can simply use Xor drawing
  763. mode, that is, put yourself in Xor, draw the frame of the rectangle, draw 
  764. it again (this will make the first one disappear), move it x pixels in the
  765. direction you are going and repeat (draw twice, move, draw twice, move, etc)
  766.  
  767. Note that you can get fancy if you want to and draw more than just the icons
  768. rectangle (ie: look at the Finder, it outlines the icon _and_ the text of the
  769. icon).
  770.  
  771. You can also use an offscreen bitmap/pixmap to make the dragging very smooth.
  772. It depends on what you need. This approach will work whether or not you use
  773. an offscreen.
  774.  
  775. Hope this helps.
  776.  
  777.  
  778.  
  779.  
  780.  
  781.  
  782.  
  783.  
  784. - -- 
  785. - -- joe zobkiw                      Internet: zobkiw@world.std.com
  786. - --                                      AOL: AFL Zobkiw  
  787. - -- mac.synthesis.MIDI.THINK C.OOP.asm   CI$: 70712,515 
  788. - -- communications.networks.cool tunes...
  789.  
  790. ---------------------------
  791.  
  792. From: de19@umail.umd.edu (Dana S Emery)
  793. Subject: Is This Fond PostScript ?!
  794. Date: 9 Jun 92 06:55:42 GMT
  795. Organization: Personal
  796.  
  797. In article <14271@ucdavis.ucdavis.edu>, lim@iris.ucdavis.edu (Lloyd Lim) writes:
  798. > In article <10s9ocINNdd2@agate.berkeley.edu> ewylie@ocf.berkeley.edu (Elizabeth Wylie) writes:
  799. > >
  800. > >I am trying to determine whether a particular font (given a font name and
  801. > >number) has a PostScript counterpart that will be handled by ATM. I've
  802. > >been told that ATM has some callback routines that would help me out,
  803. > >but I don't know what these routines are.
  804. > >
  805.  
  806. > Yes, the procedure is named fontAvailableATM.  It's not hard but it's
  807. > a bit long to describe here.
  808.  
  809. Suitcase is able to access some field in the FOND which defines the
  810. PS font name (ie TimesRomBol), so ATM shouldnt be necesary (unless one
  811. also needed to confirm the existance of the related 'LWFN').  I vaguely
  812. remember some doc on this, but cant place it just now.
  813.  
  814. DSE (de19@umail.umd.edu)
  815.  
  816.  
  817. +++++++++++++++++++++++++++
  818.  
  819. From: orpheus@reed.edu (P. Hawthorne)
  820. Date: 9 Jun 92 18:49:19 GMT
  821. Organization: Reed College, Portland, Oregon
  822.  
  823.  
  824.   ewylie@ocf.berkeley.edu (Elizabeth Wylie) writes:
  825. . I am trying to determine whether a particular font (given a font name and
  826. . number) has a PostScript counterpart that will be handled by ATM. I've been
  827. . told that ATM has some callback routines that would help me out, but I
  828. . don't know what these routines are.
  829.  
  830.   lim@iris.ucdavis.edu (Lloyd Lim) writes:
  831. . Yes, the procedure is named fontAvailableATM.  It's not hard but it's
  832. . a bit long to describe here.
  833.  
  834.   de19@umail.umd.edu (Dana S Emery) writes:
  835. . Suitcase is able to access some field in the FOND which defines the
  836. . PS font name (ie TimesRomBol), so ATM shouldnt be necesary (unless one
  837. . also needed to confirm the existance of the related 'LWFN').  I vaguely
  838. . remember some doc on this, but cant place it just now.
  839.  
  840.   In the good old days before there was any such thing as TrueImage,
  841. ahem, you could tell if a FOND resource was for a PostScript typeface
  842. by whether the style map offset in the FONDRec was greater than zero. I
  843. dunno if this has changed with True Type, frankly. Once you got the
  844. printer font file name that you wanted, you could see if the file was
  845. present with OpenResFile, I believe. OpenResFile would traverse the poor
  846. man's search path and do it's best to find the printer font.
  847.  
  848.   Since the question specifically has to do with whether ATM can deal
  849. with the font, it would probably be best to use the ATM backdoor
  850. interface. The best documentation for this (as well as the most lucid,
  851. descriptive and salient discussion of the FOND resource) is available
  852. from Adobe Developer Technical Support. They have a mail server and a
  853. telephone number, but I cannot seem to find pointers to those at the
  854. moment, but you could call the main desk.
  855.  
  856.   As Lloyd said, ATM provides a routine to answer your question. It's
  857. called fontAvailableATM. Before you use it you have to get the backdoor
  858. interface working. Adobe assumes you are using Think C and they have been
  859. unable to come up with a backdoor interface for other compilers. The
  860. package is available for anonymous ftp on sumex-aim.stanford.edu.
  861.  
  862.   Just in case, here is my code for using ATM with Think Pascal. It worked
  863. fine once, but the caveat is that I haven't used or looked at for quite
  864. some time. The last version of ATM I tested it with was 2.0.3, I think. 
  865.  
  866.   I haven't cleaned it up at all, so there may not be disassembly on all of
  867. the inlines, since they were handcompiled with MacsBug before I even got
  868. the Motorola user manuals. The inlines are for use only by the routines
  869. that actually call on the ATM backdoor, so you should not use any of the
  870. whateverJump routines, just whatever.
  871.  
  872. - ----------- Cut here and you'll have to buy a new monitor
  873.  
  874. Type
  875.   FixedMatrix = Record
  876.     a, b, c, d, tx, ty: Fixed;
  877.    End;
  878.   FixedMatrixPtr = ^FixedMatrix;
  879.  
  880.   ATMProcs3 = Record
  881.     Version: Longint;
  882.     fontAvailableATMProc: ProcPtr;
  883.     showTextATMProc: ProcPtr;
  884.     xyshowTextATMProc: ProcPtr;
  885.    End;
  886.  
  887.  
  888. {initATM initializes the ATM interface, returns 1 if ATM itself is available}
  889. {and the procsets are correctly initialized}
  890.  
  891.  Function initATM: Integer;
  892.   Type
  893.    ParamBlockRecPtr = ^ParamBlockRec;
  894.   Var
  895.    a: Ptr;
  896.    c: ParamBlockRecPtr;
  897.    result: OSErr;
  898.  
  899.   Procedure Fail;
  900.   Begin
  901.   initATM := 0;
  902.   Exit(initATM);
  903.   End;
  904.  
  905.  Begin
  906.  atmOpen := false;
  907.  
  908. {Do you have inline for NewClearPtr? If so, you may wanna use it, or ask me.}
  909. {This should work fine though.}
  910.  Ptr(c) := NewPtr(SizeOf(ParamBlockRec));
  911.  
  912.  If c = Nil Then
  913.   Fail;
  914.  c^.ioCompletion := Nil;
  915.  atmProcs.version := ATMProcs3Version;
  916.  result := OpenDriver('.ATM', c^.ioRefNum);
  917.  If (result <> noErr) Then
  918.   Fail;
  919.  a := @atmProcs;
  920.  BlockMove(@a, @c^.csParam, 4);
  921.  c^.csCode := ATMProcsStatusCode;
  922.  result := PBStatus(@c^, false);
  923.  If (result <> noErr) Then
  924.   Fail;
  925.  
  926.  a := Ptr(Clean(atmProcs.fontAvailableATMProc) + 2);
  927.  BlockMove(a, @atmProcs.fontAvailableATMProc, 4);
  928.  a := Ptr(Clean(atmProcs.showTextATMProc) + 2);
  929.  BlockMove(a, @atmProcs.showTextATMProc, 4);
  930.  a := Ptr(Clean(atmProcs.xyshowTextATMProc) + 2);
  931.  BlockMove(a, @atmProcs.xyshowTextATMProc, 4);
  932.  
  933.  atmOpen := true;
  934.  initATM := 1;
  935.  End;
  936.  
  937.  
  938.  Function fontAvailableATMJump (style, family: Integer; aProc: ProcPtr):
  939. Integer;
  940.  Inline
  941.   $205F, $4E90, $3E80;
  942.  
  943. {fontAvailableATM returns 1 iff ATM can image this family and style}
  944.  
  945.  Function fontAvailableATM (family, style: Integer): Integer;
  946.  Begin
  947.  If Not atmOpen Then
  948.   fontAvailableATM := 0
  949.  Else
  950.   fontAvailableATM := fontAvailableATMJump(style, family,
  951. atmProcs.fontAvailableATMProc);
  952.  End;
  953.  
  954.  
  955.  Function showTextATMJump (matrix: Univ Ptr; length: Integer; text: Univ Ptr;
  956. aProc: ProcPtr): Integer;
  957.  Inline
  958.   $205F, {pop into a0}
  959.   $4E90, {jsr to a0}
  960.   $48C0, {clean d0}
  961.   $3F00; {push d0}
  962.  
  963. {showTextATM shows length characters starting at text transformed by the}
  964. {specified matrix. Returns the number of characters not shown. Matrix maps}
  965. {one point character space to device space, relative to current pen}
  966. {position. Matrix's tx and ty components are updated.}
  967.  
  968.  Function showTextATM (text: Ptr; length: Integer; Var Matrix: FixedMatrix):
  969. Integer;
  970.  Begin
  971.  If Not atmOpen Then
  972.   showTextATM := length
  973.  Else
  974.   showTextATM := showTextATMJump(@matrix, length, text,
  975. atmProcs.showTextATMProc);
  976.  End;
  977.  
  978.  
  979.  Function xyshowTextATMJump (displacements, matrix: Univ Ptr; length: Integer;
  980. text: Univ Ptr; aProc: ProcPtr): Integer;
  981.  Inline
  982.   $205F, {pop into a0}
  983.   $4E90, {jsr to a0}
  984.   $48C0, {clean d0}
  985.   $3F00; {push d0}
  986.  
  987. {Show length characters starting at text transformed by the specified}
  988. {matrix. Matrix maps one point character space to device space, relative to}
  989. {current pen position. Matrix's tx and ty components are updated. Character}
  990. {x and y widths are specified by displacements. Returns the number of}
  991. {characters not shown}
  992.  
  993.  Function xyshowTextATM (text: Ptr; length: Integer; Var Matrix,
  994. Displacements: FixedMatrix): Integer;
  995.  Begin
  996.  If Not atmOpen Then
  997.   xyshowTextATM := length
  998.  Else
  999.   xyshowTextATM := xyshowTextATMJump(@displacements, @matrix, length, text,
  1000. atmProcs.xyshowTextATMProc);
  1001.  End;
  1002.  
  1003. - ------------ Wish I could put the scissors character from Zapf Dingbats here.
  1004.  
  1005. Theus
  1006. orpheus@reed.edu
  1007.  
  1008. ---------------------------
  1009.  
  1010. From: peter@cujo.curtin.edu.au (Peter N Lewis)
  1011. Subject: Warning: THINK Pascal glue for GetZoneList is dangerous!
  1012. Organization: Curtin University of Technology
  1013. Date: Mon, 8 Jun 1992 09:50:21 GMT
  1014.  
  1015. Hi All,
  1016.  
  1017. Consider yourselves warned: The THINK Pascal (don't know about MPW)
  1018. glue code for GetZoneList and GetLocalZones is dangerous, it blats
  1019. the word at location A0+$1C before it sets A0 to point to the 
  1020. paramblock.  This can cause any number of possible errors, therefore
  1021. the GetZoneList and GetLocalZones call should be avoided.  Fortunately,
  1022. all they do is fill in a few fields in the paramblock record and call
  1023. PBControl, so you can avoid them easily enough - once you know you
  1024. should!  This applies for THINK Pascal 4.0.1, I don't know about earlier
  1025. versions...
  1026.  
  1027. Take (lots of!) care,
  1028.    Peter.
  1029.  
  1030. GETZONELIST
  1031. +0010  0002FE  LINK       A6,#$0000                          
  1032. +0014  000302  SUBQ.W     #$2,A7                             
  1033. +0016  000304  PEA        -$025C(A5)                         
  1034. +001A  000308  CLR.B      -(A7)                              
  1035. +001C  00030A  JSR        Anon10+$011C        ; Call GetZoneList
  1036. +0020  00030E  MOVE.W     (A7)+,-$0102(A5)                   
  1037. +0024  000312  UNLK       A6                                 
  1038. +0026  000314  JSR        Anon1               ; 00000004     
  1039. +002A  000318  UNLK       A6                                 
  1040. +002C  00031A  RTS                                           
  1041.  
  1042. +011C  000280  MOVE.W     #$00F6,D0                          
  1043. +0120  000284  MOVE.W     #$0006,$001C(A0)   <-------------- BAD BAD BAD!       
  1044. +0126  00028A  MOVE.W     #$0006,D2                          
  1045. +012A  00028E  BRA.S      Anon10+$014E        ; 000002B2     
  1046.  
  1047. +++++++++++++++++++++++++++
  1048.  
  1049. From: siegel@world.std.com (Rich Siegel)
  1050. Date: 8 Jun 92 14:14:14 GMT
  1051. Organization: GCC Technologies
  1052.  
  1053. In article <1992Jun8.095021.21443@cujo.curtin.edu.au> peter@cujo.curtin.edu.au (Peter N Lewis) writes:
  1054. >Hi All,
  1055. >
  1056. >Consider yourselves warned: The THINK Pascal (don't know about MPW)
  1057. >glue code for GetZoneList and GetLocalZones is dangerous, it blats
  1058. >the word at location A0+$1C before it sets A0 to point to the 
  1059. >paramblock.  This can cause any number of possible errors, therefore
  1060. >the GetZoneList and GetLocalZones call should be avoided.  Fortunately,
  1061. >all they do is fill in a few fields in the paramblock record and call
  1062. >PBControl, so you can avoid them easily enough - once you know you
  1063. >should!  This applies for THINK Pascal 4.0.1, I don't know about earlier
  1064. >versions...
  1065. >
  1066. >Take (lots of!) care,
  1067. >   Peter.
  1068. >
  1069. >GETZONELIST
  1070. >+0010  0002FE  LINK       A6,#$0000                          
  1071. >+0014  000302  SUBQ.W     #$2,A7                             
  1072.  
  1073.     Just out of curiosity, where did you get this 'glue' for GetZoneList;
  1074. and what library did you add to your project? There are a couple of strange
  1075. things here: first, the disassembly you gave is nothing at all like the
  1076. disassembly that DumpObj gives for the ZoneList module from THINK Pascal's
  1077. nAppleTalk.Lib; second, there are only a few MacsBug symbols in the interface
  1078. glue libraries, and "GETZONELIST" isn't one of them, so why does your
  1079. disassembly have one?; third, what sort of program is executing here, that
  1080. the disassembly address is not in the system heap and not in the application
  1081. heap, but somewhere very low in memory?
  1082.  
  1083.     The DumpObj output for GetZoneList from MPW's own Interface.o and
  1084. THINK Pascal 4.0's "nAppleTalk.Lib" are virtually identical, and neither
  1085. one bears any resemblance to the disassembly you've posted.
  1086.  
  1087.     I think it would be wise to refrain from posting any alarms until 
  1088. this is completely figured out; it's not as cut-and-dried as you seem to
  1089. think.
  1090.  
  1091. R.
  1092. - -- 
  1093. - -----------------------------------------------------------------------
  1094. Rich Siegel                              Internet: siegel@world.std.com
  1095. Software Engineer & Toolsmith
  1096. GCC Technologies
  1097.  
  1098. +++++++++++++++++++++++++++
  1099.  
  1100. From: REEKES@applelink.apple.com (Jim Reekes)
  1101. Date: 9 Jun 92 07:46:28 GMT
  1102. Organization: Apple Computer, Inc.
  1103.  
  1104. In article <1992Jun8.095021.21443@cujo.curtin.edu.au>, peter@cujo.curtin.edu.au (Peter N Lewis) writes:
  1105. > Hi All,
  1106. > Consider yourselves warned: The THINK Pascal (don't know about MPW)
  1107. > glue code for GetZoneList and GetLocalZones is dangerous, it blats
  1108. > the word at location A0+$1C before it sets A0 to point to the 
  1109. > paramblock.  This can cause any number of possible errors, therefore
  1110. > the GetZoneList and GetLocalZones call should be avoided.  Fortunately,
  1111. > all they do is fill in a few fields in the paramblock record and call
  1112. > PBControl, so you can avoid them easily enough - once you know you
  1113. > should!  This applies for THINK Pascal 4.0.1, I don't know about earlier
  1114. > versions...
  1115. > Take (lots of!) care,
  1116. >    Peter.
  1117. > GETZONELIST
  1118. > +0010  0002FE  LINK       A6,#$0000                          
  1119. > +0014  000302  SUBQ.W     #$2,A7                             
  1120. > +0016  000304  PEA        -$025C(A5)                         
  1121. > +001A  000308  CLR.B      -(A7)                              
  1122. > +001C  00030A  JSR        Anon10+$011C        ; Call GetZoneList
  1123. > +0020  00030E  MOVE.W     (A7)+,-$0102(A5)                   
  1124. > +0024  000312  UNLK       A6                                 
  1125. > +0026  000314  JSR        Anon1               ; 00000004     
  1126. > +002A  000318  UNLK       A6                                 
  1127. > +002C  00031A  RTS                                           
  1128. > +011C  000280  MOVE.W     #$00F6,D0                          
  1129. > +0120  000284  MOVE.W     #$0006,$001C(A0)   <-------------- BAD BAD BAD!       
  1130. > +0126  00028A  MOVE.W     #$0006,D2                          
  1131. > +012A  00028E  BRA.S      Anon10+$014E        ; 000002B2     
  1132.  
  1133.  
  1134. This is the current MPW 3.2 glue.  It does the right thing.
  1135.  
  1136.  
  1137. 0000013C: 303C 00F6      MOVE.W     #$00F6,D0
  1138. 00000140: 343C 0006      MOVE.W     #$0006,D2
  1139. 00000144: 6022           BRA.S      *+$0024             ; 00000168
  1140.  
  1141. 00000168: 225F           MOVEA.L    (A7)+,A1
  1142. 0000016A: 121F           MOVE.B     (A7)+,D1
  1143. 0000016C: 205F           MOVEA.L    (A7)+,A0
  1144. 0000016E: 3142 001C      MOVE.W     D2,$001C(A0)
  1145. 00000172: 317C FFD7 0018 MOVE.W     #$FFD7,$0018(A0)
  1146. 00000178: 3140 001A      MOVE.W     D0,$001A(A0)
  1147. 0000017C: 4A01           TST.B      D1
  1148. 0000017E: 6604           BNE.S      *+$0006             ; 00000184
  1149. 00000180: A004           _Control                       ; A004
  1150. 00000182: 6002           BRA.S      *+$0004             ; 00000186
  1151. 00000184: A404           _Control   ,Sys                ; A404
  1152. 00000186: 3E80           MOVE.W     D0,(A7)
  1153. 00000188: 4ED1           JMP        (A1)
  1154.  
  1155.  
  1156. - -----------------------------------------------------------------------
  1157. Jim Reekes, Polterzeitgeist  |     Macintosh Toolbox Engineering
  1158.                              |          Sound Manager Expert
  1159. Apple Computer, Inc.         | "All opinions expressed are mine, and do
  1160. 20525 Mariani Ave. MS: 81-KS |   not necessarily represent those of my
  1161. Cupertino, CA 95014          |       employer, Apple Computer Inc."
  1162.  
  1163. +++++++++++++++++++++++++++
  1164.  
  1165. From: peter@cujo.curtin.edu.au (Peter N Lewis)
  1166. Date: 10 Jun 92 03:31:41 GMT
  1167. Organization: NCRPDA, Curtin University
  1168.  
  1169. In article <BpJ67r.CCB@world.std.com>, siegel@world.std.com (Rich Siegel) writes:
  1170. > In article <1992Jun8.095021.21443@cujo.curtin.edu.au> peter@cujo.curtin.edu.au (Peter N Lewis) writes:
  1171.  
  1172. > >Consider yourselves warned: The THINK Pascal (don't know about MPW)
  1173. > >glue code for GetZoneList and GetLocalZones is dangerous, it blats
  1174. > >the word at location A0+$1C before it sets A0 to point to the 
  1175. > >paramblock.  This can cause any number of possible errors, therefore
  1176. > >the GetZoneList and GetLocalZones call should be avoided.  Fortunately,
  1177. > >all they do is fill in a few fields in the paramblock record and call
  1178. > >PBControl, so you can avoid them easily enough - once you know you
  1179. > >should!  This applies for THINK Pascal 4.0.1, I don't know about earlier
  1180. > >versions...
  1181.  
  1182. >     Just out of curiosity, where did you get this 'glue' for GetZoneList;
  1183. > and what library did you add to your project? There are a couple of strange
  1184. > things here: first, the disassembly you gave is nothing at all like the
  1185. > disassembly that DumpObj gives for the ZoneList module from THINK Pascal's
  1186. > nAppleTalk.Lib; second, there are only a few MacsBug symbols in the interface
  1187. > glue libraries, and "GETZONELIST" isn't one of them, so why does your
  1188. > disassembly have one?; third, what sort of program is executing here, that
  1189. > the disassembly address is not in the system heap and not in the application
  1190. > heap, but somewhere very low in memory?
  1191.  
  1192. I wish you had brought this up with me in Email, but since you want it in 
  1193. public, thats fine, it means more people will find out about, and avoid, this
  1194. problem.  The glue code for GetZoneList comes from the nAppleTalk.lib file,
  1195. straight off my original THINK Pascal 4.00 disks.  The disassembly is 
  1196. nothing like what DumpObj gives simply because it was disassembled using
  1197. ResEdit's code disassembler - I can understand how many people would be
  1198. unaware that its possible to get the text of the disassembly out of ResEdit,
  1199. since it involves selecting the hexdump on the right, choosing copy to
  1200. get the disassembly.  Obviously the numbers are small since they are
  1201. offsets into procedures (anonymous ones in the library).  The GETZONELIST
  1202. is the name of the program, and thus the symbol appears before the start
  1203. of the main line code.
  1204.  
  1205. >     The DumpObj output for GetZoneList from MPW's own Interface.o and
  1206. > THINK Pascal 4.0's "nAppleTalk.Lib" are virtually identical, and neither
  1207. > one bears any resemblance to the disassembly you've posted.
  1208.  
  1209. Yes, you are quite right - they are "virtually" identical.  And if you look
  1210. at the glue code for GETZONELIST you will notice that one of the bits that
  1211. is not identical is the fact that the THINK Pascal GetZoneList and 
  1212. GetLocalZones glue code blatts a word in memory addressed as $1C(A0) 
  1213. and THEN sets up A0, whereas the MPW glue does not blatt this word 
  1214. until after it has set A0 to point to the paramblock...
  1215.  
  1216. >     I think it would be wise to refrain from posting any alarms until 
  1217. > this is completely figured out; it's not as cut-and-dried as you seem to
  1218. > think.
  1219.  
  1220. Curious - I thought it was wise after discovering a potentially dangerous
  1221. bug and thoroughly verifying its existance to warn people of the problem.
  1222. I also think it would be wise to check whether such a warning is in fact 
  1223. correct before posting suggesting that it is not.
  1224.  
  1225. If you are not interested in the details of this bug, read no further.
  1226.  
  1227. For your reading pleasure I will now give the full and gorry details
  1228. of the bug, from Project file to assembly code error:
  1229.  
  1230. The project file consists of:
  1231. Runtime.Lib        - straight off the original TP4.00 disk
  1232. Interfaces.Lib     - straight off the original TP4.00 disk
  1233. nAppleTalk.Lib     - straight off the original TP4.00 disk
  1234. AppleTalk.p        - The AppleTalk interface file
  1235. GetZoneList.p      - My test code.
  1236.  
  1237. GetZoneList.p is:
  1238. program GetZoneList;
  1239.  
  1240.  uses
  1241.   AppleTalk;
  1242.  
  1243.  var
  1244.   pb: XPPParamBlock;
  1245.   oe: OSErr;
  1246. begin
  1247.  oe := GetZoneList(@pb, false);
  1248. end.
  1249.  
  1250. NOTE: Don't ever run the above program, it is simple a call to GetZoneList 
  1251. so that I can look at the compiled code resource and check what is happening.
  1252. Obviously to use GetZoneList in practice you would need to set up many
  1253. fields of the record.
  1254.  
  1255. And now a disassembly of CODE resource id 1, got from the ResEdit code
  1256. editor.  I have removed the hexdump info normally on the right of the 
  1257. listing, since it doesn't fit in 80 columns, and have removed the 
  1258. initialization procedures, so that only the main line and the XPP glue 
  1259. procedure are left.  If you want the rest, you can compile the above 
  1260. program or mail me...
  1261.  
  1262. This procedure contains the glue code for XPP calls:
  1263. Anon10
  1264. +0000  000164  MOVE.W     #$0017,D0                                
  1265. +0004  000168  BRA        Anon10+$0176        ; 000002DA           
  1266. +0008  00016C  MOVE.W     #$0018,D0                                
  1267. +000C  000170  BRA        Anon10+$0176        ; 000002DA           
  1268. +0010  000174  MOVE.W     #$0019,D0                                
  1269. +0014  000178  BRA        Anon10+$0176        ; 000002DA           
  1270. +0018  00017C  MOVE.W     #$00F5,D0                                
  1271. +001C  000180  BRA        Anon10+$00CA        ; 0000022E           
  1272. +0020  000184  MOVE.W     #$00F4,D0                                
  1273. +0024  000188  BRA        Anon10+$00CA        ; 0000022E           
  1274. +0028  00018C  MOVE.W     #$00F3,D0                                
  1275. +002C  000190  BRA        Anon10+$00CA        ; 0000022E           
  1276. +0030  000194  MOVE.W     #$00F8,D0                                
  1277. +0034  000198  BRA        Anon10+$00CA        ; 0000022E           
  1278. +0038  00019C  MOVE.W     #$00F7,D0                                
  1279. +003C  0001A0  BRA        Anon10+$00CA        ; 0000022E           
  1280. +0040  0001A4  MOVE.W     #$00F6,D0                                
  1281. +0044  0001A8  BRA        Anon10+$00CA        ; 0000022E           
  1282. +0048  0001AC  MOVE.W     #$00FD,D0                                
  1283. +004C  0001B0  BRA.S      Anon10+$00CA        ; 0000022E           
  1284. +004E  0001B2  MOVE.W     #$00FB,D0                                
  1285. +0052  0001B6  BRA.S      Anon10+$00CA        ; 0000022E           
  1286. +0054  0001B8  MOVE.W     #$00FA,D0                                
  1287. +0058  0001BC  BRA.S      Anon10+$00CA        ; 0000022E           
  1288. +005A  0001BE  MOVE.W     #$00FC,D0                                
  1289. +005E  0001C2  BRA.S      Anon10+$00CA        ; 0000022E           
  1290. +0060  0001C4  MOVE.W     #$0100,D0                                
  1291. +0064  0001C8  BRA.S      Anon10+$00CA        ; 0000022E           
  1292. +0066  0001CA  MOVE.W     #$00FE,D0                                
  1293. +006A  0001CE  BRA.S      Anon10+$00CA        ; 0000022E           
  1294. +006C  0001D0  MOVE.W     #$0102,D0                                
  1295. +0070  0001D4  BRA.S      Anon10+$00CA        ; 0000022E           
  1296. +0072  0001D6  MOVE.W     #$0103,D0                                
  1297. +0076  0001DA  BRA.S      Anon10+$00CA        ; 0000022E           
  1298. +0078  0001DC  MOVE.W     #$00FE,D0                                
  1299. +007C  0001E0  BRA.S      Anon10+$00BE        ; 00000222           
  1300. +007E  0001E2  MOVE.W     #$00FA,D0                                
  1301. +0082  0001E6  BRA.S      Anon10+$00BE        ; 00000222           
  1302. +0084  0001E8  MOVE.W     #$00FF,D0                                
  1303. +0088  0001EC  BRA.S      Anon10+$00BE        ; 00000222           
  1304. +008A  0001EE  MOVE.W     #$00FD,D0                                
  1305. +008E  0001F2  BRA.S      Anon10+$00BE        ; 00000222           
  1306. +0090  0001F4  MOVE.W     #$00FC,D0                                
  1307. +0094  0001F8  BRA.S      Anon10+$00BE        ; 00000222           
  1308. +0096  0001FA  MOVE.W     #$00FB,D0                                
  1309. +009A  0001FE  BRA.S      Anon10+$00BE        ; 00000222           
  1310. +009C  000200  MOVE.W     #$0100,D0                                
  1311. +00A0  000204  BRA.S      Anon10+$00BE        ; 00000222           
  1312. +00A2  000206  MOVE.W     #$00F9,D0                                
  1313. +00A6  00020A  BRA.S      Anon10+$00BE        ; 00000222           
  1314. +00A8  00020C  MOVE.W     #$00F8,D0                                
  1315. +00AC  000210  BRA.S      Anon10+$00BE        ; 00000222           
  1316. +00AE  000212  MOVE.W     #$0102,D0                                
  1317. +00B2  000216  BRA.S      Anon10+$00BE        ; 00000222           
  1318. +00B4  000218  MOVE.W     #$0101,D0                                
  1319. +00B8  00021C  BRA.S      Anon10+$00BE        ; 00000222           
  1320. +00BA  00021E  MOVE.W     #$0103,D0                                
  1321. +00BE  000222  MOVEA.L    $0006(A7),A0                             
  1322. +00C2  000226  MOVE.W     #$FFF5,$0018(A0)                         
  1323. +00C8  00022C  BRA.S      Anon10+$0136        ; 0000029A           
  1324. +00CA  00022E  MOVEA.L    $0006(A7),A0                             
  1325. +00CE  000232  MOVE.W     #$FFF6,$0018(A0)                         
  1326. +00D4  000238  BRA.S      Anon10+$0136        ; 0000029A           
  1327. +00D6  00023A  MOVE.W     #$00FF,D0                                
  1328. +00DA  00023E  BRA.S      Anon10+$0136        ; 0000029A           
  1329. +00DC  000240  MOVE.W     #$00FE,D0                                
  1330. +00E0  000244  BRA.S      Anon10+$0136        ; 0000029A           
  1331. +00E2  000246  MOVE.W     #$00F8,D0                                
  1332. +00E6  00024A  BRA.S      Anon10+$0136        ; 0000029A           
  1333. +00E8  00024C  MOVE.W     #$00F9,D0                                
  1334. +00EC  000250  BRA.S      Anon10+$0136        ; 0000029A           
  1335. +00EE  000252  MOVE.W     #$00F7,D0                                
  1336. +00F2  000256  BRA.S      Anon10+$0136        ; 0000029A           
  1337. +00F4  000258  MOVE.W     #$00FC,D0                                
  1338. +00F8  00025C  BRA.S      Anon10+$0136        ; 0000029A           
  1339. +00FA  00025E  MOVE.W     #$00FD,D0                                
  1340. +00FE  000262  BRA.S      Anon10+$0136        ; 0000029A           
  1341. +0100  000264  MOVE.W     #$00FB,D0                                
  1342. +0104  000268  BRA.S      Anon10+$0136        ; 0000029A           
  1343. +0106  00026A  MOVE.W     #$00FA,D0                                
  1344. +010A  00026E  BRA.S      Anon10+$0136        ; 0000029A           
  1345. Here is the entry point for the GetLocalZones glue code     
  1346. +010C  000270  MOVE.W     #$00F6,D0                                
  1347. +0110  000274  MOVE.W     #$0005,$001C(A0)   <--- Note no set up of A0
  1348. +0116  00027A  MOVE.W     #$0005,D2                                
  1349. +011A  00027E  BRA.S      Anon10+$014E        ; 000002B2      
  1350. Here is the entry point for the GetZoneList glue code     
  1351. +011C  000280  MOVE.W     #$00F6,D0             
  1352. +0120  000284  MOVE.W     #$0006,$001C(A0)  <--- Note no set up of A0
  1353. +0126  00028A  MOVE.W     #$0006,D2                                
  1354. +012A  00028E  BRA.S      Anon10+$014E        ; 000002B2           
  1355. +012C  000290  MOVE.W     #$00F6,D0                                
  1356. +0130  000294  MOVE.W     #$0007,D2                                
  1357. +0134  000298  BRA.S      Anon10+$014E        ; 000002B2           
  1358. +0136  00029A  MOVEA.L    (A7)+,A1                                 
  1359. +0138  00029C  MOVE.B     (A7)+,D1                                 
  1360. +013A  00029E  MOVEA.L    (A7)+,A0                                 
  1361. +013C  0002A0  MOVE.W     D0,$001A(A0)                             
  1362. +0140  0002A4  TST.B      D1                                       
  1363. +0142  0002A6  BNE.S      Anon10+$0148        ; 000002AC           
  1364. +0144  0002A8  _Control                       ; A004               
  1365. +0146  0002AA  BRA.S      Anon10+$014A        ; 000002AE           
  1366. +0148  0002AC  _Control   ,Sys                ; A404               
  1367. +014A  0002AE  MOVE.W     D0,(A7)                                  
  1368. +014C  0002B0  JMP        (A1)                                     
  1369. GetZoneList and GetLocalZones set up D0 and D2, blatt a word and then 
  1370. continue here with a PBControl call:
  1371. +014E  0002B2  MOVEA.L    (A7)+,A1                                 
  1372. +0150  0002B4  MOVE.B     (A7)+,D1                           
  1373. Ahh, finally we load A0 with the address of the param block - a bit late now.      
  1374. +0152  0002B6  MOVEA.L    (A7)+,A0                                 
  1375. The next line correctly sets the word, AFTER loading A0.  The previous 
  1376. assignement to $1C(A0) in the glue code is in error and should be removed.
  1377. +0154  0002B8  MOVE.W     D2,$001C(A0) 
  1378. +0158  0002BC  MOVE.W     #$FFD7,$0018(A0)                         
  1379. +015E  0002C2  MOVE.W     D0,$001A(A0)                             
  1380. +0162  0002C6  TST.B      D1                                       
  1381. +0164  0002C8  BNE.S      Anon10+$016A        ; 000002CE           
  1382. +0166  0002CA  _Control                       ; A004               
  1383. +0168  0002CC  BRA.S      Anon10+$016C        ; 000002D0           
  1384. +016A  0002CE  _Control   ,Sys                ; A404               
  1385. +016C  0002D0  MOVE.W     D0,(A7)                                  
  1386. +016E  0002D2  JMP        (A1)                                     
  1387. +0170  0002D4  SUBI.B     #$5850,$5000(A6)    ; 'P'                
  1388. +0176  0002DA  MOVEA.L    $0004(A7),A0                             
  1389. +017A  0002DE  MOVEA.L    AtalkHk2,A1                              
  1390. +017E  0002E2  MOVE.L     (A7)+,(A7)                               
  1391. +0180  0002E4  JSR        $0002(A1)                                
  1392. +0184  0002E8  MOVEA.L    (A7)+,A0                                 
  1393. +0186  0002EA  MOVE.W     D0,-(A7)                                 
  1394. +0188  0002EC  JMP        (A0) 
  1395.  
  1396. And this is the main line code:                                    
  1397. GETZONELIST
  1398. +0000  0002EE  JSR        Anon1+$0016         ; 0000001A           
  1399. +0004  0002F2  JSR        Anon7               ; 00000138           
  1400. +0008  0002F6  JSR        Anon4               ; 000000E2           
  1401. +000C  0002FA  JSR        Anon5+$000A         ; 000000F8           
  1402. +0010  0002FE  LINK       A6,#$0000                                
  1403. +0014  000302  SUBQ.W     #$2,A7                                   
  1404. +0016  000304  PEA        -$025C(A5)                               
  1405. +001A  000308  CLR.B      -(A7)                                    
  1406. +001C  00030A  JSR        Anon10+$011C   <--- Here is the call to GetZoneList
  1407. Note that no set up of A0 is done at this end either.  Tracing back we
  1408. find that the last assignment of A0 is in Anon5, either to the stack 
  1409. pointer A7, or set by SetApplLimit, MacApplZone, or MoreMasters (if any of
  1410. those traps modify A0).
  1411. +0020  00030E  MOVE.W     (A7)+,-$0102(A5)                         
  1412. +0024  000312  UNLK       A6                                       
  1413. +0026  000314  JSR        Anon1               ; 00000004           
  1414. +002A  000318  UNLK       A6                                       
  1415. +002C  00031A  RTS                                                 
  1416. +002E  00031C  DC.B       $80+$0B, 'GETZONELIST'                   
  1417. +003A  000328  DC.W       $0000               ; size of literals   
  1418.  
  1419. I have verified that the MPW glue does not contain this error.  And I am
  1420. 100% confident that the nAppleTalk.Lib glue as supplied on my original
  1421. 4.00 INTERNATIONAL original disk contains this error, and therefore 
  1422. writes to a random word in memory (worse a word just off A0, which will
  1423. likely be pointing at something important).  Since this can easily cause
  1424. a crash (it would address error if A0 happened to be odd), or can cause
  1425. all sorts of subtle behaviour.  I have no qualms about posting this, and
  1426. I hope it doesn't bite anyone else.
  1427.  
  1428. Take (as I said before, lots of!) care,
  1429.    Peter.
  1430.  
  1431. ______________________________________________________________________
  1432. Peter N Lewis, NCRPDA, Curtin University      peter@cujo.curtin.edu.au
  1433. GPO Box U1987, Perth WA 6001, AUSTRALIA            FAX: +61 9 367 8141
  1434.  
  1435. +++++++++++++++++++++++++++
  1436.  
  1437. From: keith@taligent.com (Keith Rollin)
  1438. Date: 10 Jun 92 21:11:19 GMT
  1439. Organization: Taligent
  1440.  
  1441. In article <1992Jun10.033141.6872@cujo.curtin.edu.au>, peter@cujo.curtin.edu.au
  1442. (Peter N Lewis) writes:
  1443. > > In article <1992Jun8.095021.21443@cujo.curtin.edu.au>
  1444. peter@cujo.curtin.edu.au (Peter N Lewis) writes:
  1445. > > >Consider yourselves warned: The THINK Pascal (don't know about MPW)
  1446. > > >glue code for GetZoneList and GetLocalZones is dangerous, it blats
  1447. > > >the word at location A0+$1C before it sets A0 to point to the 
  1448. > > >paramblock.
  1449. > I have verified that the MPW glue does not contain this error.
  1450. >
  1451.  
  1452. I think that the problem is limited to THINK Pascal (as long as Rich or someone
  1453. else with THINK Pascal can verify the problem). A number of people have verified
  1454. that it does _not_ exist in MPW, and I just checked THINK C 5.0.2 and it seems
  1455. OK, too.
  1456.  
  1457. - --
  1458. Keith Rollin
  1459. Phantom Programmer
  1460. Taligent, Inc.
  1461.  
  1462. ---------------------------
  1463.  
  1464. End of C.S.M.P. Digest
  1465. **********************
  1466.